package com.ruoyi.camera.util;

import com.ruoyi.camera.domain.AimpCamera;
import com.ruoyi.camera.service.IAimpCameraService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class RtspPackage {

    @Autowired
    private IAimpCameraService aimpCameraService;

    private final String MAIN_TYPE = "0";

    public String rtspBuild(String id, String type) {
        String rtsp = "";
        AimpCamera aimpCamera = aimpCameraService.selectAimpCameraById(id);
        System.out.println(aimpCamera.toString());
        switch (aimpCamera.getCameraType()) {

            case "华为":
                if(type.equals(MAIN_TYPE)) {
                    rtsp = aimpCamera.getRtsp().substring(0,aimpCamera.getRtsp().length()-1) + "1";
                } else {
                    rtsp = aimpCamera.getRtsp().substring(0,aimpCamera.getRtsp().length()-1) + "2";
                }
            break;

            case "大华":
                if(type.equals(MAIN_TYPE)) {
                    rtsp = aimpCamera.getRtsp().substring(0,aimpCamera.getRtsp().length()-1) + "0";
                } else {
                    rtsp = aimpCamera.getRtsp().substring(0,aimpCamera.getRtsp().length()-1) + "1";
                }
                break;

            case "海康":
                if(type.equals(MAIN_TYPE)) {
                    String[] inf = aimpCamera.getRtsp().split("/");
                    rtsp = inf[0] + "//" + inf[2] + "/"+ inf[3] + "/"+ inf[4] + "/" + "main" + inf[6];
                } else {
                    String[] inf = aimpCamera.getRtsp().split("/");
                    rtsp = inf[0] + "//" + inf[2] + "/"+ inf[3] + "/"+ inf[4] + "/" + "sub" + inf[6];
                }
                break;
        }

        return rtsp;
    }
}
